#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
  pid_t pid;
  int pipefd[2];
  if (pipe(pipefd) < 0) {
    perror("pipe");
    exit(1);
  }

  pid = fork();

  if (pid > 0) {
    // parent
    close(pipefd[0]);
    write(pipefd[1], "hello", 5);
    close(pipefd[1]);
    wait(NULL);
    exit(0);
  }
  else if (pid == 0) {
    // child
    close(pipefd[1]);
    char buf[50];
    int len = read(pipefd[0], buf, 50);
    printf("%d\n", len);
    write(1, buf, len);
    close(pipefd[0]);
    exit(0);
  }
  else {
    perror("fork");
    exit(1);
  }
  exit(0);
}
